<?php

	$infoboxes = new info_boxes();

	class test_model {
		public $username;
		public $emailaddress;
		public $password;
		public $hidden = 'This is the hidden value';
		public $gender;
		public $message;
		public $response;
		public $radios;

		public function validate_username() {
			if (empty($this->username)) {
				return(false);
			}

			return(true);
		}

		public function sanitize_emailaddress() {
			return($this->emailaddress . '-sanitized');
		}

		public function validate_emailaddress() {
			$ret = new n2f_return();

			if (empty($this->emailaddress)) {
				$ret->isFail();
				$ret->addMsg('Invalid email address supplied.');
			} else {
				$ret->isGood();
			}

			return($ret);
		}


		public static function genderOptions() {
			return(array(
				'Test Group'	=> array(
					'value1'	=> 'Text 1',
					'value2'	=> 'Text 2'
				),
				'value3'		=> 'Text 3',
				'value4'		=> 'Text 4'
			));
		}

		public static function radioOptions() {
			return(array(
				"value1" => "This is value one",
				"value2" => "This is value two",
				"value3" => "This is value three"
			));
		}
	}

	class test_model_two {
		public $testing;
	}

	$tmp = new test_model();
	$tmp2 = new test_model_two();

	$fh = new formhelper('testform', $tmp);
	$fh2 = new formhelper('testform2', $tmp2);

	if ($fh->isPosted()) {
		if ($fh->isValid()) {
			$infoboxes->throwSuccess('', 'Form submitted and valid!', '');
		} else {
			$infoboxes->throwError('', 'The form submitted was invalid.', '');

			$msgs = $fh->getErrors();

			if (count($msgs) > 0) {
				foreach (array_values($msgs) as $msg) {
					$infoboxes->throwError('', '- ' . $msg, '');
				}
			}
		}
	}

	if ($fh2->isPosted()) {
		if ($fh2->isValid()) {
			$infoboxes->throwSuccess('', 'Second form submitted and valid!', '');
		} else {
			$infoboxes->throwError('', 'Second form was invalid.', '');
		}
	}

	$tpl = new n2f_template('dynamic');
	$tpl->setModule('main')->setFile('index');
	$tpl->setField('infoboxes', $infoboxes);
	$tpl->render()->display();

?>